#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,l,vll;
int d[200000],vvv[200000],a[200000];
int p[200000],p1[200000];
int ans=0;
int yy[100005][1000];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        ans=0;
        cin>>n>>m>>l>>vll;
        for(int j=1;j<=n;j++){
            cin>>d[j]>>vvv[j]>>a[j];
        }
        for(int j=1;j<=m;j++){
            cin>>p[j];
        }
        for(int j=1;j<=n;j++){
            int yy=0;
            if(vvv[j]>vll){
                for(int e=1;e<=m;e++){
                    if(p[e]>=d[j]){
                        ans++;
                        break;
                    }
                }
            }

        }
    cout<<ans<<" ";
    if(ans==0){
        cout<<m;
    }
    else{
        cout<<m-1;
    }
        }

    return 0;
}
